package com.xwltz.admin.controller;

import com.xwltz.admin.service.IAlbumService;
import com.xwltz.admin.model.response.AlbumResponse;
import com.xwltz.cache.utils.CaffeineCache;
import com.xwltz.cache.utils.RedisCache;
//import com.xwltz.common.file.cos.CosUtils;
import com.xwltz.database.page.TableList;
import com.xwltz.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "相册管理")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/album")
@Slf4j
@SuppressWarnings("unused")
public class AlbumController extends BaseController {

	private final IAlbumService albumService;

	@GetMapping("/index")
	@ApiOperation(value = "分页查询相册列表")
	public TableList<AlbumResponse> index() {
		var query = new AlbumResponse();
		var list = albumService.getPageList(query);
		System.out.println(list);
		return list;
	}

	@GetMapping("/getById")
	public AlbumResponse getById(Long id) {
		var model = albumService.getById(id);
		RedisCache.STRING.set("album:" + model.getId(), model);
		return model;
	}

	@GetMapping("/get")
	public AlbumResponse get(Long id) {
		var model = RedisCache.STRING.get("album:" + id, AlbumResponse.class);
		CaffeineCache.getCache.add("values", model);
		var model2 = CaffeineCache.getCache.get("values");
		System.out.println(model2);
		return model;
	}

//	@GetMapping("/getUrl")
//	public String getUrl() {
//		var url = CosUtils.Instance.getObjectByPublic("xwltz-1252948963", "appVersion.txt");
//		return url;
//	}
}
